/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine SDK - core/memory
// Copyright( c) 2013.  All Rights Reserved
//
// File:		AEEngineSystem.cpp
// Author:		Gianluca Belardelli
// Date:		11/04/2014
//
/////////////////////////////////////////////////////////////////////////
#include <AEEngine.h>

////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
///		An int enum, used to index the types of systems.
///		Custom systems do not have predefined types.  Their types are made with
///		System::Types::MakeCustom(), so they're not listed here.
/// </summary>
/// <seealso cref="System::Types::MakeCustom()"/>
////////////////////////////////////////////////////////////////////////////////////////////////
enum AESystemIndices //TypeIndices
{
	// Standard types
	AENotUsed = 0,
	AEDefGenericSystem,
	AEDefGeometrySystem,
	AEDefGraphicsSystem,
	AEDefPhysicsCollisionSystem,
	AEDefAudioSystem,
	AEDefInputSystem,
	AEDefAISystem,
	AEDefAnimationSystem,
	AEDefScriptingSystem,
	AEDefWaterSystem,
	AESysIndicesMaxIndex
};

const AEUINT32 AEEngineSystem::AENullSystem				= 0;
const AEUINT32 AEEngineSystem::AEGenericSystem			= ( 1 << AEDefGenericSystem );
const AEUINT32 AEEngineSystem::AEGeometrySystem			= ( 1 << AEDefGeometrySystem );
const AEUINT32 AEEngineSystem::AEGraphicsSystem			= ( 1 << AEDefGraphicsSystem );
const AEUINT32 AEEngineSystem::AEPhysicsCollisionSystem	= ( 1 << AEDefPhysicsCollisionSystem );
const AEUINT32 AEEngineSystem::AEAudioSystem			= ( 1 << AEDefAudioSystem );
const AEUINT32 AEEngineSystem::AEInputSystem			= ( 1 << AEDefInputSystem );
const AEUINT32 AEEngineSystem::AEAISystem				= ( 1 << AEDefAISystem );
const AEUINT32 AEEngineSystem::AEAnimationSystem		= ( 1 << AEDefAnimationSystem );
const AEUINT32 AEEngineSystem::AEScriptingSystem		= ( 1 << AEDefScriptingSystem );
const AEUINT32 AEEngineSystem::AEWaterSystem			= ( 1 << AEDefWaterSystem );

AEEngineSystem::AEEngineSystem( void ) : m_bInitialized(0), m_lpPropList(0L)
{
	
}

AE_FORCEINLINE AEUINT32 AEEngineSystem::MakeCustomSystemID( AEUINT32 uiZeroBasedIndex )
{
	return 1 << ( AESysIndicesMaxIndex + uiZeroBasedIndex );
};

AEFLOAT32 AEEngineSystem::GetCPUUsage( void )
{
	return 0.0f;
}

#pragma intrinsic(_BitScanForward)
//#pragma intrinsic(_BitScanForward64)

AEUINT32 AEEngineSystem::GetSystemIndex( AEUINT32 uiSystemType )
{
    AEUINT32 uiIndex = static_cast<AEUINT32>(-1);
#ifdef AE_PLATFORM_WIN32
    _BitScanForward( (unsigned long*)&uiIndex, uiSystemType );
#endif
    return uiIndex;
};
